package com.ruoyi.legal.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.ResponseModel;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.Pages;
import com.ruoyi.common.utils.DateUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.legal.domain.PackYstz;
import com.ruoyi.legal.service.IPackYstzService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
/**
 * 移送台账备份Controller
 * 
 * @author xwj
 * @date 2025-05-11
 */
@RestController
@RequestMapping("/legal/packYstz")
@Api(tags = "移送台账备份")
public class PackYstzController extends BaseController {
    @Autowired
    private IPackYstzService packYstzService;

    /**
     * 查询移送台账备份列表
     */
    @PostMapping("/list")
    @ApiOperation("分页查询")
    public TableDataInfo list(@RequestBody PackYstz packYstz) {
        startPage();
        List<PackYstz> list = packYstzService.selectPackYstzList(packYstz);
        return getDataTable(list);
    }

    @PostMapping("/listAll")
    @ApiOperation("不分页查询")
    public AjaxResult listAll(@RequestBody PackYstz packYstz) {
        startOrderBy();
        List<PackYstz> list = packYstzService.selectPackYstzList(packYstz);
        return success(list);
    }

    /**
     * 导出移送台账备份列表
     */
    @Log(title = "移送台账备份", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出")
    public void export(HttpServletResponse response, PackYstz packYstz) {
        List<PackYstz> list = packYstzService.selectPackYstzList(packYstz);
        ExcelUtil<PackYstz> util = new ExcelUtil<PackYstz>(PackYstz.class);
        util.exportExcel(response, list, "移送台账备份数据");
    }

    /**
     * 获取移送台账备份详细信息
     */
    @GetMapping(value = "/info/{id}")
    @ApiOperation("详情")
    public AjaxResult info(@PathVariable("id") Long id)  {
        return success(packYstzService.selectPackYstzById(id));
    }

    /**
     * 新增移送台账备份
     */
    @Log(title = "移送台账备份", businessType = BusinessType.INSERT)
    @PostMapping("/save")
    @ApiOperation("新增")
    public AjaxResult save(@RequestBody PackYstz packYstz) {
        SysUser user = getLoginUser().getUser();
        if(packYstz.getId() == null) {
        packYstz.setCreateId(user.getUserId());
            packYstz.setCreateTime(DateUtils.getNowDate());
            packYstz.setCreateBy(user.getNickName());
            packYstzService.insertPackYstz(packYstz);
        } else {
            packYstz.setUpdateId(user.getUserId());
            packYstz.setUpdateTime(DateUtils.getNowDate());
            packYstz.setUpdateBy(user.getNickName());
            packYstzService.updatePackYstz(packYstz);
        }

        return success(packYstz);
    }

    /**
     * 修改移送台账备份
     */
    @Log(title = "移送台账备份", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    @ApiOperation("修改")
    public AjaxResult update(@RequestBody PackYstz packYstz) {
        SysUser user = getLoginUser().getUser();
                packYstz.setUpdateId(user.getUserId());
                packYstz.setUpdateTime(DateUtils.getNowDate());
                packYstz.setUpdateBy(user.getNickName());
        return success(packYstzService.updatePackYstz(packYstz));
    }

    /**
     * 删除移送台账备份
     */
    @Log(title = "移送台账备份", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除或批量删除")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(packYstzService.deletePackYstzByIds(ids));
    }

    @Log(title = "移送台账备份", businessType = BusinessType.DELETE)
    @PostMapping("/delete")
    @ApiOperation("条件删除")
    public ResponseModel delete(@RequestBody PackYstz packYstz) {
        int num = packYstzService.delete(packYstz);
        return ResponseModel.of(num);
    }

    @PostMapping("/queryPage")
    @ApiOperation("分页查询-mp")
    public ResponseModel<Pages<PackYstz>> queryPage(@RequestBody PackYstz packYstz) {
        Pages<PackYstz> page = packYstzService.queryPage(packYstz);
        return ResponseModel.of(page);
    }
}
